package demo.isolib.movement {
	import as3isolib.geom.Pt;
	
	import com.greensock.TimelineLite;
	import com.greensock.TweenLite;
	import com.greensock.easing.Linear;
	
	import demo.isolib.Tile;
	import demo.isolib.TileEvent;
	import com.sshc625.log.Logger;
	
	public class SmoothMove extends TileMovement {
		
		public function SmoothMove(spd:uint=100) {
			Logger.log("new SmoothMove.execute()");
			super(spd);
		}
		
		override public function execute(params:Array = null):void {
			Logger.log("SmoothMove.execute(" + params + ")"+super.tile.name);
			super.execute(params);
			updateAstarGrid(true);	
					
			var x:Number = params[0] * tile.grid.cellSize;
			var y:Number = params[1] * tile.grid.cellSize;
			var z:Number = params[2];
			
			var distance:uint = Pt.distance(new Pt(super.tile.x, super.tile.y), new Pt(x, y));
			var obj:Object = {x:x, y:y, ease:Linear.easeNone, onStart:this.onMoveStart, onComplete:this.onMoveComplete, onUpdate:this.onMoveUpdate};
			TweenLite.to(super.tile, distance/super.speed, obj);
			
			updateAstarGrid(tile.walkable);
		}
		
		protected function onMoveAbort():void {
			super.abort();
		}		
		protected function onMoveStart():void {
			//Logger.log("SmoothMove.onMoveStart(" + arguments + ")");
			super.tile.isIdle = false;
			super.start();
		}
		
		protected function onMoveComplete():void {
			//Logger.log("SmoothMove.onMoveComplete(" + arguments + ")");
			updateAstarGrid(tile.walkable);
			tile.isIdle = true;
			super.complete();
		}
		
		protected function onMoveUpdate():void {
			super.update();	
		}
	}
	
}